package com.wk1un2.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wk1un2.service.ResourceuseService;
import com.wk1un2.util.Result;

@RestController
public class ResourceuseController {// 资源使用记录控制层
	@Autowired
	private ResourceuseService resourceuseservice;

	@RequestMapping("/getAllResourceuse")
	public Object getAll(@RequestParam Map<String, Object> map) {
		Integer page = Integer.parseInt(map.get("page").toString());
		Integer limit = Integer.parseInt(map.get("limit").toString());
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		Result res = new Result(0, "", resourceuseservice.count(map), resourceuseservice.getAll(map));
		return res;
	}

	@RequestMapping("/getBook") // 图书图表
	public Object getBook(@RequestParam Map<String, Object> map) {
		Result res = new Result(0, "true", resourceuseservice.getBook(map).size(), resourceuseservice.getBook(map));
		return res;
	}

	@RequestMapping("/getComp") // 电脑图表
	public Object getComp(@RequestParam Map<String, Object> map) {
		Result res = new Result(0, "true", resourceuseservice.getComp(map).size(), resourceuseservice.getComp(map));
		return res;
	}

	@RequestMapping("/addResourceuse")
	public Object add(@RequestParam Map<String, Object> map) {
		Result res = new Result(0, "", resourceuseservice.add(map), true);
		return res;
	}

	@RequestMapping("/updateResourceuse")
	public Object update(@RequestParam Map<String, Object> map) {
		Result res = new Result(0, "", resourceuseservice.update(map), true);
		return res;
	}

	@RequestMapping("/deleteResourceuse")
	public Object delete(Integer resuse_id) {
		Result res = new Result(0, "", resourceuseservice.delete(resuse_id), true);
		return res;
	}
}
